* 6_MechanismsStateLegislature_Overleaf
** Goal: examine state legislature data
** Beatrice Lee
** Date Created: 2024-06-18
** Last Updated: 2024-07-11 // bal

cd "$Data/Processing"
use state_elections_panel_df5_20240709, clear

***************************************** dep var ***********************************
sum state_sen_ctrl_gub_pty state_house_ctrl_gub_pty if (year >= 2020 & year <= 2022 & office == "gub")
sum state_sen_ctrl_sen_pty state_house_ctrl_sen_pty if (year >= 2020 & year <= 2022 & office == "senate")

sum state_sen_ctrl_gub_pty state_house_ctrl_gub_pty if (year > 2012 & office == "gub")
sum state_sen_ctrl_sen_pty state_house_ctrl_sen_pty if (year > 2012 & office == "senate")

***************************************** state legislature vars ************************************
* Note: focus this analysis on the gubernatorial races

*1) 2sls

eststo clear

*** A. Did Aid Impact Share of State Senate Controlled by Incumbent Gov's Party?
eststo: ivregress 2sls state_sen_ctrl_gub_pty lag_state_sen_ctrl_gub_pty norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022 & office == "gub"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

*** B. Did Aid Impact Share of State House Controlled by Incumbent Gov's Party?
eststo: ivregress 2sls state_house_ctrl_gub_pty lag_state_house_ctrl_gub_pty norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022 & office == "gub"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

*** C. Did Aid Impact Share of State Senate Controlled by Incumbent Senator's Party?
eststo: ivregress 2sls state_sen_ctrl_sen_pty lag_state_sen_ctrl_sen_pty norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022 & office == "senate"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

*** D. Did Aid Impact Share of State House Controlled by Incumbent Senator's Party?
eststo: ivregress 2sls state_house_ctrl_sen_pty lag_state_house_ctrl_sen_pty norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022 & office == "senate"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

**** Export Table to Latex
cd "$Results"
esttab using "state_leg_2sls_20240709.tex", replace /// Replace file if it already exists
 collabels("\multicolumn{1}{c}{1l}" "\multicolumn{1}{c}{l2}" "\multicolumn{1}{c}{13}" "\multicolumn{1}{c}{14}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"\(F\)"')) drop(_cons) ///
 booktabs ///
 title("State Legislature 2sls") ///
 addnotes("Note: TKTKTKTK")

*2) panel sample 

eststo clear

*** A. Did Aid Impact Share of State Senate Controlled by Incumbent Gov's Party?

*** no controls, no fe
eststo: reg state_sen_ctrl_gub_pty lag_state_sen_ctrl_gub_pty c.reps_per_million##i.duringpandemic if (year > 2012 & office == "gub") , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

** all fes
eststo: reghdfe state_sen_ctrl_gub_pty lag_state_sen_ctrl_gub_pty c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if (year > 2012 & office == "gub") , vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

*** B. Did Aid Impact Share of State House Controlled by Incumbent Gov's Party?

*** no controls, no fe
eststo: reg state_house_ctrl_gub_pty lag_state_house_ctrl_gub_pty c.reps_per_million##i.duringpandemic if (year > 2012 & office == "gub"), vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

** all fes
eststo: reghdfe state_house_ctrl_gub_pty lag_state_house_ctrl_gub_pty c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if (year > 2012 & office == "gub"), vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

*** C. Did Aid Impact Share of State Senate Controlled by Incumbent Senator's Party?

*** no controls, no fe
eststo: reg state_sen_ctrl_sen_pty lag_state_sen_ctrl_sen_pty c.reps_per_million##i.duringpandemic if (year > 2012 & office == "senate") , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

** all fes
eststo: reghdfe state_sen_ctrl_sen_pty lag_state_sen_ctrl_sen_pty c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if (year > 2012 & office == "senate"), vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

*** D. Did Aid Impact Share of State House Controlled by Incumbent Senator's Party?

*** no controls, no fe
eststo: reg state_house_ctrl_sen_pty lag_state_house_ctrl_sen_pty c.reps_per_million##i.duringpandemic if (year > 2012 & office == "senate"), vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

** all fes
eststo: reghdfe state_house_ctrl_sen_pty lag_state_house_ctrl_sen_pty c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if (year > 2012 & office == "senate"), vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

****** Export Table to Latex
cd "$Results/"
esttab using "state_leg_panel_20240709.tex", replace ///
 collabels("\multicolumn{1}{c}{col1}" "\multicolumn{1}{c}{col2}" "\multicolumn{1}{c}{col3}" "\multicolumn{1}{c}{col4}" "\multicolumn{1}{c}{col5}" "\multicolumn{1}{c}{col6}" "\multicolumn{1}{c}{col7}" "\multicolumn{1}{c}{col8}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 office_fe year_fe state_fe norm_vote_year_fe office_state_fe, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"Office FE"' `"Year FE"' `"State FE"' `"Normal Vote x Year FE"' `"Office x State FE"')) drop(_cons) ///
 booktabs /// 
 title("State Legislature panel") ///
 addnotes("Note: TKTKTKTK")
